package pers.liyan.shi.computermanager.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.liyan.shi.computermanager.core.Result;
import pers.liyan.shi.computermanager.util.SystemUtil;

/**
 * @author ShiLY
 * @version 1.0
 * @date 2020/2/10 23:13
 */
@Slf4j
@RestController
@RequestMapping("/manager/rest")
public class ManagerRestController {

    @Value("${computer.shutdown.seconds}")
    private int shutdownSeconds;

    @Value("${computer.restart.seconds}")
    private int restartSeconds;

    @Autowired
    private SystemUtil systemUtil;

    @PostMapping("/shutdown")
    public Result shutdown() {
        log.info("rest call shutdown");
        return systemUtil.execCmdRtResult("shutdown -s -t " + shutdownSeconds);

    }

    @PostMapping("/cancel")
    public Result cancelShutdown() {
        log.info("rest call cancel");
        return systemUtil.execCmdRtResult("shutdown -a");
    }

    @PostMapping("/restart")
    public Result restart() {
        log.info("rest call restart");
        return systemUtil.execCmdRtResult("shutdown -r -t " + restartSeconds);
    }

}
